package com.yuan;

import com.yuan.bean.Person;
import com.yuan.config.MainConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainTest {
    public static void main(String[] args) {
        //xml配置的方式
        /*ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean.xml");
        Person person = (Person) applicationContext.getBean("person");
        System.out.println(person);*/

        //使用注解的方式为IOC容器注册一个组件
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class);
        Person person = applicationContext.getBean(Person.class);
        System.out.println(person);
        //根据类型获取bean的名称
        String[] beanNamesForType = applicationContext.getBeanNamesForType(Person.class);
        for (int i=0;i<beanNamesForType.length;i++){
            System.out.println(beanNamesForType[i]);
        }
    }
}
